package com.xiaohua.api.controller;

import com.xiaohua.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xiaohua.common.annotation.Log;
import com.xiaohua.common.core.controller.BaseController;
import com.xiaohua.common.core.domain.AjaxResult;
import com.xiaohua.common.enums.BusinessType;
import com.xiaohua.api.domain.XhApiCredentials;
import com.xiaohua.api.service.IXhApiCredentialsService;
import com.xiaohua.common.utils.poi.ExcelUtil;
import com.xiaohua.common.core.page.TableDataInfo;

/**
 * API凭证管理Controller
 *
 * @author 小花
 * @date 2025-03-27
 */
@RestController
@RequestMapping("/api/credentials" )
public class XhApiCredentialsController extends BaseController {
    @Autowired
    private IXhApiCredentialsService xhApiCredentialsService;

/**
 * 查询API凭证管理列表
 */
@PreAuthorize("@ss.hasPermi('api:credentials:list')" )
@GetMapping("/list" )
    public TableDataInfo list(XhApiCredentials xhApiCredentials) {
        startPage();
        List<XhApiCredentials> list = xhApiCredentialsService.selectXhApiCredentialsList(xhApiCredentials);
        return getDataTable(list);
    }

    /**
     * 导出API凭证管理列表
     */
    @PreAuthorize("@ss.hasPermi('api:credentials:export')" )
    @Log(title = "API凭证管理" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, XhApiCredentials xhApiCredentials) {
        List<XhApiCredentials> list = xhApiCredentialsService.selectXhApiCredentialsList(xhApiCredentials);
        ExcelUtil<XhApiCredentials> util = new ExcelUtil<XhApiCredentials>(XhApiCredentials. class);
        util.exportExcel(response, list, "API凭证管理数据" );
    }

    /**
     * 获取API凭证管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('api:credentials:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return success(xhApiCredentialsService.selectXhApiCredentialsById(id));
    }

    /**
     * 新增API凭证管理
     */
    @PreAuthorize("@ss.hasPermi('api:credentials:add')" )
    @Log(title = "API凭证管理" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XhApiCredentials xhApiCredentials) {
        return toAjax(xhApiCredentialsService.insertXhApiCredentials(xhApiCredentials));
    }

    /**
     * 修改API凭证管理
     */
    @PreAuthorize("@ss.hasPermi('api:credentials:edit')" )
    @Log(title = "API凭证管理" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XhApiCredentials xhApiCredentials) {
        return toAjax(xhApiCredentialsService.updateXhApiCredentials(xhApiCredentials));
    }

    /**
     * 删除API凭证管理
     */
    @PreAuthorize("@ss.hasPermi('api:credentials:remove')" )
    @Log(title = "API凭证管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(xhApiCredentialsService.deleteXhApiCredentialsByIds(ids));
    }
}